package de.jonasjelten.jcalc.mathExps;

import de.jonasjelten.jcalc.exception.JEvaluationException;
import de.jonasjelten.jcalc.math.JNumber;

/**
 *
 * @author michael, jonas
 */
public abstract class JSingleArgMathExp extends JMathExp {
    public JMathExp arg;

    public JSingleArgMathExp(JMathExp arg) {
        super(arg.jcalc);
        this.arg = arg;
    }

    @Override
    public JNumber eval() throws JEvaluationException{
        arg.init();
        return arg.getEvalResult();
    }

    /**
     * Gets the String of the JSingleArgMathExp, e.g. Fac and Neg
     * @param bracket do you want brackets arround it
     * @param operandbeforenumber should the operand be before the number
     * @param operand the symbol of the used mathexp
     * @return the human-friendly string
     */
    public String toString(boolean bracket, boolean operandbeforenumber, String operand) {
        String res = "";
        if (operandbeforenumber) {
            res = operand + arg;
        } else {
            res = arg + operand;
        }

        if (bracket) {
            res = "("+res+")";
        }
        return res;
    }

    @Override
    public abstract boolean isTrivial();

    @Override
    public int getNonTrivialChildCount() {
        return arg.getNonTrivialMathExpsCount();
    }
}
